package homework;

import java.util.Arrays;
import java.util.Random;
class Solution {
	public static int removeElement(int[] nums, int val) {
		Arrays.sort(nums);
		int cur=0;
		int pre=0;
		int k =0;
		for(int i =0;i<nums.length;i++) {
			if(nums[i]==val) {
				pre=i;
				cur=i;
				break;
			}
		}
		while(cur<nums.length) {
			if(nums[++cur]==val) {
				++cur;
				k++;
			}
		}
		for(int i =cur;i<nums.length;i++) {
			nums[pre]=nums[cur-k];
		}
		return nums.length-k;
	}

	public static void main(String[] args) {
		int [] arr={2,3,3,2};
		System.out.println(removeElement(arr, 3));
	}
}
public class test9 {
	public static int func(int [] arr) {
		int cur=1;
		int pre=0;
		while(cur<arr.length) {
			if(arr[pre]==arr[cur]) {
				cur++;
			} else {
				arr[++pre]=arr[cur];
				cur++;
			}
		}
		return pre+1;
	}

	public static void main(String[] args) {
		Random random=new Random();
		int i =5;
		while(i>0) {
			int len=random.nextInt(100);
			System.out.println(len);
			i--;
		}
	}
	public static void main1(String[] args) {
		int [] arr=new int[]{0,0,1,1,2,2,3,3,4,4,};
		System.out.println(func(arr));
	}
}
